/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.fzhucc.modules.sciTechnologyDemand.repository;

import com.fzhucc.modules.sciPersonnelInfo.domain.SciPersonnelInfo;
import com.fzhucc.modules.sciTechnologyDemand.domain.SciTechnologyDemand;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author yyg
 * @website https://eladmin.vip
 * @date 2023-11-28
 **/
public interface SciTechnologyDemandRepository extends JpaRepository<SciTechnologyDemand, Integer>, JpaSpecificationExecutor<SciTechnologyDemand> {

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and is_show = 1 and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormal(String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 ")
    List<SciTechnologyDemand> findNoDelete();

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and is_show = 1  and org_area=:area and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByArea(String area, String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and is_show = 1 and org_area like :area and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeArea(String area, String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and org_area like :area and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeAreaWithOutIsShow(String area, String auditStatus);


    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and audit_status=:auditStatus and create_time<=NOW() and create_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowCSeven(String area, String auditStatus, Date atime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and audit_status=:auditStatus and delete_time<=NOW() and delete_time>=:dtime")
    int findNormalByLikeAreaWithOutIsShowDSeven(String area, String auditStatus, Date dtime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0  and audit_status=:auditStatus and create_time<=NOW() and create_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowCSevenFJS(String auditStatus, Date atime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0  and audit_status=:auditStatus and delete_time<=NOW() and delete_time>=:dtime")
    int findNormalByLikeAreaWithOutIsShowDSevenFJS(String auditStatus, Date dtime);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeAreaWithOutIsShowFJS(String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and audit_status=:auditStatus LIMIT 1")
    List<SciTechnologyDemand> findNormalByLikeAreaWithOutIsShowFJSLimitOne(String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and org_area like :area and audit_status!=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeAreaWithOutIsShowNoPass(String area, String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and org_area like :area and technology like :technology and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeTechnologyWithOutIsShow(String technology, String auditStatus, String area);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and technology like :technology and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeTechnologyWithOutIsShowFJS(String technology, String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and org_area like :area and retype like :retype and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeReTypeWithOutIsShow(String retype, String auditStatus, String area);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and retype like :retype and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeReTypeWithOutIsShowFJS(String retype, String auditStatus);


    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and retype like :retype  and audit_status=:auditStatus and create_time<=NOW() and create_time>=:atime")
    int findNormalByLikeReTypeWithOutIsShowCSeven(String retype, String auditStatus, Date atime, String area);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and retype like :retype  and audit_status=:auditStatus and delete_time<=NOW() and delete_time>=:dtime")
    int findNormalByLikeReTypeWithOutIsShowDSeven(String retype, String auditStatus, Date dtime, String area);


    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and retype like :retype  and audit_status=:auditStatus and create_time<=NOW() and create_time>=:atime")
    int findNormalByLikeReTypeWithOutIsShowFJSCSeven(String retype, String auditStatus, Date atime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and retype like :retype  and audit_status=:auditStatus and delete_time<=NOW() and delete_time>=:dtime")
    int findNormalByLikeReTypeWithOutIsShowFJSDSeven(String retype, String auditStatus, Date dtime);


    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and do_status like :doStatus and audit_status=:auditStatus and create_time<=NOW() and create_time>=:atime")
    int findNormalByLikeDoStatusWithOutIsShowFJSCSeven(String doStatus, String auditStatus, Date atime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and do_status like :doStatus  and audit_status=:auditStatus and delete_time<=NOW() and delete_time>=:dtime")
    int findNormalByLikeDoStatusWithOutIsShowFJSDSeven(String doStatus, String auditStatus, Date dtime);


    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and do_status like :doStatus and audit_status=:auditStatus and create_time<=NOW() and create_time>=:atime")
    int findNormalByLikeDoStatusWithOutIsShowCSeven(String doStatus, String auditStatus, String area, Date atime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and do_status like :doStatus and audit_status=:auditStatus and create_time<=NOW() and create_time>=:dtime")
    int findNormalByLikeDoStatusWithOutIsShowDSeven(String doStatus, String auditStatus, String area, Date dtime);


    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and org_area like :area and do_status like :doStatus and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeDoStatusWithOutIsShow(String doStatus, String auditStatus, String area);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and do_status like :doStatus and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeDoStatusWithOutIsShowFJS(String doStatus, String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and org_area like :area and audit_status=:auditStatus order by create_time desc limit 0,4")
    List<SciTechnologyDemand> findNormalTop(String auditStatus, String area);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and audit_status=:auditStatus order by create_time desc limit 0,4")
    List<SciTechnologyDemand> findNormalTopFJS(String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and do_status like :doStatus and org_area like :area and audit_status=:auditStatus order by create_time desc limit 0,4")
    List<SciTechnologyDemand> findNormalTopWithDoStatus(String doStatus, String auditStatus, String area);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and do_status like :doStatus and audit_status=:auditStatus order by create_time desc limit 0,4")
    List<SciTechnologyDemand> findNormalTopWithDoStatusFJS(String doStatus, String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and audit_status=:auditStatus limit 50")
    List<SciTechnologyDemand> findNormalTop(String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and audit_status=:auditStatus and slogan like :name")
    List<SciTechnologyDemand> findNormalByLikeName(String auditStatus, String name);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and audit_status=:auditStatus and technology=:technology and retype like :retype and org_area like :orgArea")
    List<SciTechnologyDemand> findNormalLikeTechnologyRetypeLikeRetypeLikeOrgArea(String technology, String retype, String orgArea, String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and audit_status=:auditStatus and technology=:technology and retype like :retype")
    List<SciTechnologyDemand> findNormalByTechnologyRetype(String technology, String retype, String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where is_delete=0 and technology like :technology and audit_status=:auditStatus")
    List<SciTechnologyDemand> findNormalByLikeTechnology(String technology, String auditStatus);

    @Query(nativeQuery = true, value = "select * from tb_sci_technology_demand where data_id=:dataId")
    List<SciTechnologyDemand> findNormalByDataId(String dataId);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0  and org_area like:area and audit_status=:auditStatus")
    int findCountNormalByLikeArea(String area, String auditStatus);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0  and org_area like:area and audit_status=:auditStatus and create_time<=:eTime")
    int findCountNormalByLikeAreaWithTime(String area, String auditStatus, Date eTime);


    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and audit_status=:auditStatus and create_time<=:btime and create_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowCSevenCreate(String area, String auditStatus, Date atime, Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and audit_status=:auditStatus and delete_time<=:btime and delete_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowDSevenDel(String area, String auditStatus, Date atime, Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and audit_status like:auditStatus and create_time<=:btime and create_time>=:atime")
    int findNormalByLikeAreaWithOutIsShowCSevenCreateLikeDsh(String area, String auditStatus, Date atime, Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and audit_status like:auditStatus and create_time<=:btime ")
    int findNormalByLikeAreaWithOutIsShowCSevenCreateLikeDshWithOutS(String area, String auditStatus,  Date btime);

    @Query(nativeQuery = true, value = "select count(*) from tb_sci_technology_demand where is_delete=0 and org_area like :area and audit_status not like:auditStatus and create_time<=:btime ")
    int findNormalByLikeAreaWithOutIsShowCSevenCreateLikeDshWithOutSNotLike(String area, String auditStatus,  Date btime);
}